let animate = {
    run: async function animation($el, animations = [], finish) {
        let play = (animation) => new Promise(resolve => {
            $el.classList.add(animation.value, 'animated');
            let removeAnimation = () => {
                $el.removeEventListener('animationend', removeAnimation);
                $el.removeEventListener('animationcancel', removeAnimation);
                $el.classList.remove(animation.value, 'animated');
                resolve();
            }
                
            $el.addEventListener('animationend', removeAnimation);
            $el.addEventListener('animationcancel', removeAnimation);
        });
        for (let i = 0, len = animations.length; i < len; i++) {
            await play(animations[i]);
            if (finish) {
                finish();
            }
        }
    }
}

export default animate